<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      body {
        position: relative;
        display: grid;
        place-items: center;
        height: 100vh;
        background: url(https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2100&q=80)
          center/cover;
        transition: all 0.3s ease-out;
      }
      body::after {
        content: '';
        width: 100vw;
        height: 100vh;
        position: absolute;
        left: 0;
        top: 0;
        z-index: -1;
        background-color: rgba(0, 0, 0, 0.3);
      }
      .slide {
        opacity: 0;
        width: 100vw;
        height: 100vh;
        background: url(https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2100&q=80)
          center/cover;
        position: absolute;
        left: -15vw;
        top: -15vh;
        transition: all 0.3s ease-out;
      }
      .slide.active {
        opacity: 1;
      }
      .slider-contain {
        position: relative;
        width: 70vw;
        height: 70vh;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
        overflow: hidden;
        border-radius: 10px;
      }
      .arrow {
        position: fixed;
        top: 50%;
        left: 50%;
        width: 50px;
        height: 50px;
        border: 2px solid yellow;
        cursor: pointer;
        z-index: 11;
        transform: translate(-50%, -50%);
        font-size: 30px;
        font-weight: 900;
        text-align: center;
        align-items: 50px;
      }
      .arrow-left {
        left: calc(15vw - 30px);
      }
      .arrow-right {
        left: calc(84vw + 50px) !important;
      }
    </style>
  </head>
  <body>
    <div class="slider-contain">
      <div
        class="slide active"
        style="
          background-image: url(https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2100&q=80);
        "
      ></div>
      <div
        class="slide"
        style="
          background-image: url(https://images.unsplash.com/photo-1511593358241-7eea1f3c84e5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1934&q=80);
        "
      ></div>
      <div
        class="slide"
        style="
          background-image: url(https://images.unsplash.com/photo-1495467033336-2effd8753d51?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2100&q=80);
        "
      ></div>
      <div
        class="slide"
        style="
          background-image: url(https://images.unsplash.com/photo-1522735338363-cc7313be0ae0?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2689&q=80);
        "
      ></div>
      <div
        class="slide"
        style="
          background-image: url(https://images.unsplash.com/photo-1559087867-ce4c91325525?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2100&q=80);
        "
      ></div>

      <div class="arrow arrow-left">←</div>
      <div class="arrow arrow-right">→</div>
    </div>
  </body>
  <script>
    let con = document.querySelector('.slider-contain');
    let slides = document.querySelectorAll('.slide');
    let arrowl = document.querySelector('.arrow-left');
    let arrowr = document.querySelector('.arrow-right');
    let activeIdx = 0;
    arrowl.addEventListener('click', () => {
      activeIdx--;
      if (activeIdx < 0) {
        activeIdx = slides.length - 1;
      }
      setBodyBgImg();
      setActiveSlide();
    });
    arrowr.addEventListener('click', () => {
      activeIdx++;
      if (activeIdx >= slides.length) {
        activeIdx = 0;
      }
      setBodyBgImg();
      setActiveSlide();
    });

    function setBodyBgImg() {
      document.body.style.backgroundImage =
        slides[activeIdx].style.backgroundImage;
    }
    function setActiveSlide() {
      slides.forEach((item) => {
        item.classList.remove('active');
      });
      slides[activeIdx].classList.add('active');
    }
  </script>
</html>
